package cn.biz.imp;

import java.util.List;

import cn.biz.CartBiz;
import cn.dao.CartDao;
import cn.entity.Cart;
import cn.entity.User;

public class CartBizImp implements CartBiz {
	private CartDao cartDao;

	public CartDao getCartDao() {
		return cartDao;
	}

	public void setCartDao(CartDao cartDao) {
		this.cartDao = cartDao;
	}

	/*
	 * 添加一条Cart信息 成功返回一个success的字符串
	 * @see cn.biz.CartBiz#insert(cn.entity.Cart, java.lang.Integer, java.lang.Integer)
	 */
	@Override
	public String insert(Cart cart) {
		String result = "error";
		try {
			cartDao.insert(cart);
			result = "success";
		} catch (Exception e) {
			e.printStackTrace();
			result = "error";
		}
		return result;
	}

	/*
	 * 按照id删除一条Cart信息 成功返回一个success的字符串
	 * @see cn.biz.CartBiz#delete(java.lang.Integer)
	 */
	@Override
	public String delete(Integer id) {
		String result = "error";
		try {
			cartDao.delete(id);
			result = "success";
		} catch (Exception e) {
			e.printStackTrace();
			result = "error";
		}
		return result;
	}

	@Override
	public String insertOrUpdate(Cart cart) {
		String result = "error";
		try {
			cartDao.insertOrUpdate(cart);
			result = "success";
		} catch (Exception e) {
			e.printStackTrace();
			result = "error";
		}
		return result;
	}

	/*
	 * 更新一条Cart信息 成功返回一个success的字符串
	 * @see cn.biz.CartBiz#update(cn.entity.Cart)
	 */
	@Override
	public String update(Cart cart) {
		String result="error";
		try {
			cartDao.update(cart);
			result="success";
		} catch (Exception e) {
			e.printStackTrace();
			result="error";
		}
		return result;
	}

	@Override
	public List queryByUser(User user) {
		return cartDao.queryByUser(user);
	}
	
	@Override
	public List query(Cart cart) {
		return cartDao.query(cart);
	}

	@Override
	public List getAll() {
		return cartDao.getAll();
	}

	@Override
	public Cart getCartById(Integer id) {
		return cartDao.getCartById(id);
	}

	@Override
	public List getCartByGid(Integer gid,Integer uid) {
		return cartDao.getCartByGid(gid,uid);
	}
}
